package com.yangye.springclouddemozookeeper.utils;

import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;

/**
 * @author yangye
 * @date 2020/10/19
 */
public class ZKUtils {

	private static ZooKeeper zk;

	public static ZooKeeper getZK(Watcher watcher) {
		try {
			zk = new ZooKeeper("192.168.28.200:2181,192.168.28.201:2181,192.168.28.202:2181", 3000, watcher);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return zk;
	}

	public static void closeZK(){
		if(zk != null){
			try {
				zk.close();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
